import { WECHAT, BYTEDANCE } from 'cc/env';
import { uniConfig } from '../config/UniConfig';
import { game } from 'cc';

// 不同平台有不一样的函数，这里统一
export class UniformFunction {
  // 统一设置入口
  public shareToFriend(roomId: string, gameType: number) {
    if (WECHAT) {
      this.wxShareToFriend(roomId, gameType);
    }
    if (BYTEDANCE) {
      this.ttShareToFriend(roomId, gameType);
    }
  }
  private wxShareToFriend(roomId: string, gameType: number) {
    const res = {
      title: '双人台球游戏，快来切磋一下',
      imageUrl: uniConfig.shareImageUrl,
      query: 'roomId=' + roomId +`&gameType=${gameType}`,
    }
    wx.shareAppMessage( res );
  }
  private ttShareToFriend(roomId: string, gameType: number) {
    const res = {
      title: '双人台球游戏，快来切磋一下',
      imageUrl: uniConfig.shareImageUrl,
      query: 'roomId=' + roomId +`&gameType=${gameType}`,
    }
    tt.shareAppMessage( res );
  }
  // 统一设置入口
  public shareToGroup() {
    if (WECHAT) {
      this.wxShareToGroup();
    }
    if (BYTEDANCE) {
      this.ttShareToGroup();
    }
  }
  private wxShareToGroup() {
    const res = {
      title: '双人台球游戏，快来切磋一下',
      imageUrl: uniConfig.shareImageUrl,
      query: '',
    }
    wx.shareAppMessage( res );
  }
  private ttShareToGroup() {
    const res = {
      title: '双人台球游戏，快来切磋一下',
      imageUrl: uniConfig.shareImageUrl,
      query: '',
    }
    tt.shareAppMessage( res );
  }
  // 交换击球归自己击球时产生振动
  public vibrateShake() {
    if (WECHAT) {
      wx.vibrateShort({
        type: 'heavy',
        success: () => { console.log('vibrate short success '); },
        fail: (res: any) => { console.log('vibrate short failed ', res); },
      })
    }
  }
  public showInfoToast(content: string, duration: number) {
    if (WECHAT) {
      wx.showToast({
        title: content,
        icon: 'none',
        duration: duration
      });
    } else if (BYTEDANCE) {
      tt.showToast({
        title: content,
        duration: duration,
        success(res: any) {
          console.log(`bytedance ${res}`);
        },
        fail(res: any) {
          console.log('bytedance showToast调用失败');
        },
      });
    }
  }
  //第一个框
  public navigateToDouZiXiangQi() {
    if (WECHAT) {
      wx.navigateToMiniProgram({
        appId: 'wx4bdc31e107b6ca23',
      });
    }
  }
  //第二个框
  public navigateToTank() {
    if (WECHAT) {
      wx.navigateToMiniProgram({
        appId: 'wx64b1a1dbcbd48b47',
      });
    }
  }
   //第三个框
  public navigateToxiaoButton() {
    if (WECHAT) {
      wx.navigateToMiniProgram({
        appId: 'wxbec945fbc822fe6e',
      });
    }
  }
   //第四框
  public navigateToqingluButton() {
    if (WECHAT) {
      wx.navigateToMiniProgram({
        appId: 'wx9085016db0cc48fd',
      });
    }
  }
  //第五个框
  public navigateTowanButton() {
    if (WECHAT) {
      wx.navigateToMiniProgram({
        appId: 'wx7a5ba1d66a442875',
      });
    }
  }
  
  
  public navigateTodaButton() {
    if (WECHAT) {
      wx.navigateToMiniProgram({
        appId: 'wx4bdc31e107b6ca23',
      });
    }
  }
  
  public navigateToqinButton() {
    if (WECHAT) {
      wx.navigateToMiniProgram({
        appId: 'wxb603f593cebe6819',
      });
    }
  }
   
  //第八个框
  public navigateToyanButton() {
    if (WECHAT) {
      wx.navigateToMiniProgram({
        appId: 'wx4ce5959cfe825117',
      });
    }
  }
  
}